import axios from "axios";
//导入nprogress包对应
import NProgress from 'nprogress';
// import 'nprogress/nprogress.css'

export function request(config) {
  // 创建axios实例
  const instance = axios.create({
    baseURL: 'https://lianghj.top:8888/api/private/v1/',
    timeout: 5000,
  })
  // 2.axios拦截器
  instance.interceptors.request.use(config => {
    //展示进度条
    NProgress.start();
    // 处理请求信息 添加token
    config.headers.Authorization = window.sessionStorage.getItem('token')
    return config
  }, err => {})

  instance.interceptors.response.use(res => {
    //隐藏进度条
    NProgress.done();
    return res.data;
  }, err => {})

  return instance(config)

}